package com.sgb.member.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.sgb.member.R;
import com.sgb.member.weight.ScreenTextView;
import com.swgk.core.util.SharedPreferenceUtil;
import com.swgk.core.view.selection.CommonPopEntity;

import java.util.ArrayList;
import java.util.List;

public class TabAdapter extends RecyclerView.Adapter<TabAdapter.ViewHolder> {

    public List<CommonPopEntity> datas ;
    private Context context;

    private MatterChoose mMatterChoose;
    public void setmMatterChoose(MatterChoose mMatterChoose) {
        this.mMatterChoose = mMatterChoose;
    }

    public TabAdapter(List<CommonPopEntity> datas, Context context) {
        this.datas = datas;
//        this.datas.addAll(datas);
        this.context = context;
    }

    @NonNull
    @Override
    public TabAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.tab_item, parent, false);
        ViewHolder holder = new ViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull TabAdapter.ViewHolder holder, int position) {
        CommonPopEntity entity = datas.get(position);
        holder.tab_name.setText(entity.getCategoryName());
        holder.tab_name.setOnClickListener(v -> mMatterChoose.setPop(entity,holder.tab_name));

    }
//    public void setDatas(List<CommonPopEntity> list){
//        datas.clear();
//        datas.addAll(list);
//        notifyDataSetChanged();
//    }

//    public  List<CommonPopEntity> getAllData(){
//        return datas;
//    }

//    public void resetTabData(){
//        if(datas.size()>0){
//            datas.clear();
//            notifyDataSetChanged();
//        }
//    }

    @Override
    public int getItemCount() {
        return datas.size();
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        private ScreenTextView tab_name;
        public ViewHolder(View view) {
            super(view);
            tab_name = view.findViewById(R.id.tab_name);
        }
    }

    public interface MatterChoose{
        void setPop(CommonPopEntity entitie,ScreenTextView screenTextView);
    }
}
